﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ECONTACT.Bussiness;
using ECONTACT.DataLayer;
using System.Data;
using System.Windows.Forms;
using DevComponents.DotNetBar.Controls;
using DevComponents.Editors.DateTimeAdv;

namespace ECONTACT.Controller
{
    public class DiemCtrl
    {
        DiemData m_DiemData = new DiemData();

        #region Do du lieu vao DataGridView

        public void HienThi(DataGridViewX dGV,
                            ComboBoxEx cmbMaHS,
                            ComboBoxEx cmbMaLop,
                            ComboBoxEx cmbMaMonHoc,
                            ComboBoxEx cmbMaHocKy,
                            TextBoxX txtDiem,
                            TextBoxX txtNhanXet)
        {
            BindingSource bS = new BindingSource();
            bS.DataSource = m_DiemData.LayDsDiem();

            DataTable dT = m_DiemData.LayDsDiem();

            cmbMaHS.DataBindings.Clear();
            cmbMaHS.DataBindings.Add("SelectedValue", bS, "MaHS");

            cmbMaLop.DataBindings.Clear();
            cmbMaLop.DataBindings.Add("SelectedValue", bS, "MaLop");

            cmbMaMonHoc.DataBindings.Clear();
            cmbMaMonHoc.DataBindings.Add("SelectedValue", bS, "MaMonHoc");

            cmbMaHocKy.DataBindings.Clear();
            cmbMaHocKy.DataBindings.Add("SelectedValue", bS, "MaHocKy");

            txtDiem.DataBindings.Clear();
            txtDiem.DataBindings.Add("Text", bS, "Diem");

            txtNhanXet.DataBindings.Clear();
            txtNhanXet.DataBindings.Add("Text", bS, "NhanXet");

            dGV.DataSource = bS;
        }
        #endregion

        public String LuuDiem(String MaHS, String MaLop, String MaMonHoc, String MaHocKy, String Diem, String NhanXet)
        {
            return m_DiemData.LuuDiem(MaHS, MaLop, MaMonHoc, MaHocKy, Diem, NhanXet);
        }

        public String UpdateDiem(String MaHS, String MaLop, String MaMonHoc, String MaHocKy, String Diem, String NhanXet)
        {
            return m_DiemData.UpdateDiem(MaHS, MaLop, MaMonHoc, MaHocKy, Diem, NhanXet);
        }

        //public void XemDiem(String MaHS)
        //{
        //    m_DiemData.XemDiem(MaHS);
        //}
        public void XemDiem(ListViewEx lVXemDiem, String MaHS)
        {
            lVXemDiem.Items.Clear();

            DataTable m_DT = m_DiemData.XemDiem(MaHS);

            foreach (DataRow row in m_DT.Rows)
            {
                ListViewItem item = new ListViewItem();

                item.SubItems.Add(row["MaHS"].ToString());
                item.SubItems.Add(row["TENLOP"].ToString());
                item.SubItems.Add(row["TenMH"].ToString());
                item.SubItems.Add(row["TenHS"].ToString());
                item.SubItems.Add(row["TenHK"].ToString());
                item.SubItems.Add(row["Diem"].ToString());

                lVXemDiem.Items.Add(item);
            }
        }
    }
}
